package com.yonyou.cyxdms.sysAuth.service.interceptor;

import com.yonyou.cyx.framework.service.interceptor.ResponseDtoConfigService;
import com.yonyou.cyxdms.sysAuth.service.controller.LoginController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.MethodParameter;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 定义消息返回对象的特殊处理类
 *
 * @author: zhangxianchao
 * @since: 2018/9/18 0018
 * @updateDate:
 * @updateRemark:
 * @version:1.0 Copyright: Copyright (c) 2018
 */
@Component
public class ResponseDtoConfigServiceImpl implements ResponseDtoConfigService {

    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    private String ignoreGetRole = "/login/getRole";

    /**
     * 当处理成功后的配置
     *
     * @param request
     * @param response
     * @param body
     * @param returnType
     * @return java.lang.Object
     * @author zhangxianchao
     * @since 2018/9/18 0018
     */
    @Override
    public Object sucessResponse(ServerHttpRequest request, ServerHttpResponse response, Object body, MethodParameter
            returnType) {
        if (request.getURI().toString().equals(ignoreGetRole)) {
            logger.info("body:{}", body);
            return body;
        }
        return null;
    }

    /**
     * 当处理异常时的返回值
     *
     * @param req
     * @param error
     * @param response
     * @return java.lang.Object
     * @author zhangxianchao
     * @since 2018/9/18 0018
     */
    @Override
    public ResponseEntity exceptionResponse(HttpServletRequest req, Throwable error, HttpServletResponse response) {
        return null;
    }
}
